package com.ruoyi.common.utils;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * 自定义元数据对象处理工具
 */
@Slf4j
@Component
public class MyMetaObjectUtils implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("公共字段自动填充[insert]");
        metaObject.setValue("createTime", DateUtils.getNowDate());
        metaObject.setValue("updateTime", DateUtils.getNowDate());
        metaObject.setValue("createBy", SecurityUtils.getUsername());
        metaObject.setValue("updateBy", SecurityUtils.getUsername());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段自动填充[update]");
        metaObject.setValue("updateTime", DateUtils.getNowDate());
        metaObject.setValue("updateBy", SecurityUtils.getUsername());
    }
}
